﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace SIGERP_Datos
{
    public class Conexion
    {
        public static SqlConnection getConexion()
        {
            String cadena = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=sigerp;Integrated Security=True";
            return new  SqlConnection(cadena);
        }

        public static DataTable ejecutaSelect(String select) {
            SqlConnection conexion = getConexion();
            SqlDataAdapter adapter = new SqlDataAdapter(select, conexion);
            DataTable tabla = new DataTable();
            try
            {
                adapter.Fill(tabla);
                conexion.Close();
            }
            catch (Exception exc)
            {
                throw new ArgumentException(exc.Message);
            }

            return tabla;
        }

        public static Boolean ejecutaComando(SqlCommand comando) {
            bool se_ejecuto = false;
            SqlConnection conexion = getConexion();
            comando.Connection = conexion;
            try
            {
                conexion.Open();
                comando.ExecuteNonQuery();
                conexion.Close();
                se_ejecuto = true;
            }
            catch (Exception exc)
            {
                throw new ArgumentException(exc.Message);
            }
            return se_ejecuto;
        }
    }
}
